<template>
  <view class="container">
    <uni-list>
      <uni-list-item showExtraIcon="true" :extraIcon="{type: 'person-filled'}" title="昵称" :rightText="user.nickname" />
	  <uni-list-item showExtraIcon="true" :extraIcon="{type: 'auth-filled'}" title="姓名" :rightText="user.name" />
      <uni-list-item showExtraIcon="true" :extraIcon="{type: 'phone-filled'}" title="手机号码" :rightText="user.phone" />
      <uni-list-item showExtraIcon="true" :extraIcon="{type: 'info-filled'}" title="年龄" :rightText="user.age" />
    </uni-list>
	<button style="margin: 20rpx;" type="primary" @click="goEdit">编辑信息</button>
	<button style="margin: 20rpx;background-color: firebrick;" type="primary" @click="handleLogout()">退出登录</button>
  </view>
</template>

<script>
  import { getUserProfile } from "@/api/system/user"

  export default {
    data() {
      return {
        user: {},
        roleGroup: "",
        postGroup: ""
      }
    },
    onShow() {
      this.getUser()
    },
    methods: {
      getUser() {
        getUserProfile().then(response => {
          this.user = response.data;
		  const info = {
		  			  name: this.user.name || '',
		  			  age: this.user.age || '',
		  			  phone: this.user.phone || ''
		  		  }
		  uni.setStorageSync("user_info",info);
        })
      },
	  handleLogout() {
	    this.$modal.confirm('确定注销并退出系统吗？').then(() => {
	      this.$store.dispatch('LogOut').then(() => {}).finally(()=>{
	        this.$tab.reLaunch('/pages/index')
	      })
	    })
	  },
	  goEdit(){
		  uni.navigateTo({
		  	url:"/pages/mine/info/edit"
		  })
	  }
    }
  }
</script>

<style lang="scss">
  page {
    background-color: #ffffff;
  }
</style>
